 @include "binchop.awk"
 @include "bootstrap.awk"
 
 function bootbins(verbose,bins0,bins,tiny,conf,repeats,  \
                   id,chop,lastchop,maxchop,b,key,\
                   thischop,x,bs,vals,rank,com) {
   binchop(bins0,bins,tiny)
   lastchop = 1
   maxchop  = 1
   for(b = 1; b <= length(bins); b++) {
     key       = bins[b]["key"]
     thischop  = bins[b]["chop"]
     maxchop  += (thischop != lastchop)
     bs[maxchop][b]
     for(x in bins0[key])
       vals[maxchop][++id] = bins0[key][x]
     lastchop = thischop
   }
   rank=1
   com = "sort -t, -n -k 1 -k 3 #" rand()
   for(chop=1; chop<=maxchop; chop++) {
     if(chop != 1) 
       rank += bootstrap(vals[chop-1],vals[chop],conf,repeats)
     for(b in bs[chop]) {
       bins[b]["rank"] = rank
       if(verbose)
         printf(verbose, rank, bins[b]["key"],bins[b]["mean"]) | com
   }}
 }
